package com.freeman.cement.controller;

import com.freeman.cement.annotation.NeedRole;
import com.freeman.cement.entity.Dept;
import com.freeman.cement.entity.EventType;
import com.freeman.cement.entity.ResponseResult;
import com.freeman.cement.service.DeptService;
import com.freeman.cement.service.DutyRoomService;
import com.freeman.cement.service.EventTypeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 值班室
 */
@RestController
@RequestMapping("/dutyroom")
@CrossOrigin    //允许跨域访问
public class DutyroomController {

    @Resource
    private DeptService deptService;

    @Resource
    private EventTypeService eventTypeService;

    @Resource
    private DutyRoomService dutyRoomService;

    //注意，这里返回Object的话，不可以添加, produces = "text/plain;charset=utf-8"
    //如果是返回String的话，需要添加, produces = "text/plain;charset=utf-8"，否则中文乱码
    /**
     * 分页获取值班室列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/selectAllDutyroom", method = RequestMethod.POST)
    public ResponseResult selectAllDutyroom(@RequestParam int pageNo, @RequestParam int pageSize) {
        return deptService.selectAllDutyroom(pageNo, pageSize);
    }

    /**
     * 查询值班室详细信息
     * @param id
     * @return
     */
    @RequestMapping(value = "/getDutyRoom", method = RequestMethod.POST)
    public ResponseResult getDutyRoom(@RequestParam("id") int id){
        return deptService.getDept(id);
    }


    /**
     * 新增值班室
     * @param dept
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addDutyRoom", method = RequestMethod.POST)
    public ResponseResult addDutyRoom(Dept dept){
        dept.setIsDutyRoom(1);
        return deptService.addDept(dept);
    }

    /**
     * 删除值班室
     * @param id
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteDutyRoom", method = RequestMethod.POST)
    public ResponseResult deleteDutyRoom(@RequestParam("id") int id) {
        return deptService.deleteDept(id);
    }

    /**
     * 编辑值班室
     * @param dept
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/updateDutyRoom", method = RequestMethod.POST)
    public ResponseResult updateDutyRoom(Dept dept){
        dept.setIsDutyRoom(1);
        return deptService.updateDept(dept);
    }


    //注意，这里返回Object的话，不可以添加, produces = "text/plain;charset=utf-8"
    //如果是返回String的话，需要添加, produces = "text/plain;charset=utf-8"，否则中文乱码
    /**
     * 分页查询值班室负责处理接收的事件类型
     * @param dutyRoomId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @NeedRole("管理员||值班员")
    @RequestMapping(value = "/selectSubEventType", method = RequestMethod.POST)
    public ResponseResult selectSubEventType(@RequestParam int dutyRoomId, @RequestParam int pageNo, @RequestParam int pageSize) {
        return eventTypeService.selectSubEventType(dutyRoomId, pageNo, pageSize);
    }

    /**
     * 值班室订阅事件类型
     * @param dutyRoomId
     * @param eventType
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/addSubEventType", method = RequestMethod.POST)
    public ResponseResult addSubEventType(@RequestParam int dutyRoomId, String eventType) {
        return dutyRoomService.addSubEventType(dutyRoomId, eventType);
    }

/*    //值班室删除已订阅事件类型
    //因为selectSubEventType没有提供值班室和订阅事件关联表的id，所以这个接口不能用
    @RequestMapping(value = "/deleteSubEventType", method = RequestMethod.POST)
    public ResponseResult deleteSubEventType(@RequestParam int id) {
        return dutyRoomService.deleteSubEventTypeById(id);
    }*/

    /**
     * 值班室删除已订阅事件类型
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/deleteSubEventType", method = RequestMethod.POST)
    public ResponseResult deleteSubEventType(@RequestParam int dutyRoomId, String eventType) {
        return dutyRoomService.deleteSubEventType(dutyRoomId, eventType);
    }

    /**
     * 获取值班室所管辖摄像头个数
     * @param dutyRoomId
     * @return
     */
    @NeedRole("管理员")
    @RequestMapping(value = "/getCameraCount", method = RequestMethod.POST)
    public ResponseResult getCameraCount(@RequestParam int dutyRoomId) {
        return dutyRoomService.getCameraCount(dutyRoomId);
    }


}
